<?xml version="1.0" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lm="http://schemas.icitadel.com/Lazarus/Manifest.xsd" version="1.0">

	<xsl:output method="text"/>

	<xsl:include href="../../common.xsl" />
	<xsl:include href="../../convert.xsl" />

   <xsl:template match="lm:manifest">
		<xsl:variable name="ROOT_PATH" select="@output-path" />
		<xsl:variable name="FILTER_MASK">Database.StoredProcedure.Alter</xsl:variable>
		
		<xsl:variable name="DB_USER" select="lm:datasource/@user" />
		<xsl:variable name="DB_PASSWORD" select="lm:datasource/@password" />
		<xsl:variable name="DB_LOCATION" select="lm:datasource/@location" />
		<xsl:variable name="DB_SCHEMA" select="lm:datasource/@schema" />
		<xsl:text>@ECHO OFF
		
REM.
REM.
REM -------------------------------------------------------------------------------
REM -------------------------------------------------------------------------------
REM -- </xsl:text><xsl:value-of select="@project-name" /><xsl:text>
REM --                                                                           
REM -- AlterProcs - Alters all Stored Procedures to provide implementation details.                                      
REM --                                                                           
REM -------------------------------------------------------------------------------
REM -------------------------------------------------------------------------------
REM.
REM.
REM.

if '%1' == '' goto usage
if '%2' == '' goto usage
if '%3' == '' goto usage
if '%4' == '' goto usage

if '%1' == '/?' goto usage
if '%1' == '-?' goto usage
if '%1' == '?' goto usage
if '%1' == '/help' goto usage


@ECHO Compilation started: %DATE% %TIME%
@ECHO.
@ECHO.

</xsl:text>
		<xsl:for-each select="lm:files/lm:file[ starts-with( @type, $FILTER_MASK ) ]">
			<xsl:text>@ECHO Compiling stored procedure '</xsl:text><xsl:value-of select="@concept-name" /><xsl:text>'
</xsl:text>
			<xsl:text>osql</xsl:text>
			<xsl:text> -U %3 </xsl:text>
			<xsl:text> -P %4 </xsl:text>
			<xsl:text> -b </xsl:text>
			<xsl:text> -S %1 </xsl:text>
			<xsl:text> -d %2 </xsl:text>
			<xsl:text> -n -i "</xsl:text>
			<xsl:value-of select="@name" />
			<xsl:text>"
if %ERRORLEVEL% NEQ 0 goto errors

</xsl:text>
		</xsl:for-each>

goto finish

REM: How to use screen
:usage
@ECHO.
@ECHO Usage: AlterProcs [Server] [Database] [User] [Password]
@ECHO.
@ECHO Options:
@ECHO    Server   - the name of the target SQL Server.
@ECHO    Database - the name of the target database.
@ECHO    User     - the SQL Server account login name.
@ECHO    Password - the SQL Server account password.
@ECHO.
@ECHO Example: AlterProcs.cmd DBServer\SQL2k MainDatabase bsmith pa$$w0rd
@ECHO.
@ECHO.
goto done

REM: error handler
:errors
@ECHO.
@ECHO WARNING! Error(s) were detected!
@ECHO --------------------------------
@ECHO Please evaluate the situation and, if needed,
@ECHO restart this command file. You may need to
@ECHO supply command parameters when executing
@ECHO this command file.
@ECHO.
pause
goto done

REM: finished execution
:finish
@ECHO.
@ECHO Script execution is complete!
:done
@ECHO on
   </xsl:template>

</xsl:stylesheet>